<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ScheduleRecord extends Model
{

    protected $fillable = ['schedule_id','days','project_id','type','push_id','role_id','person_id','front_date','last_date','delay','measure','harmonize_id','harmonize','is_review','review_id'];

    const POSTONLY = ['schedule_id','days','project_id','type','push_id','role_id','person_id','front_date','last_date','delay','measure','harmonize_id','harmonize','is_review','review_id'];
    use HasFactory;

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }
    
    public function project()
    {
        return $this->hasOne(Project::class,'id','project_id')->select('id','title','status');
    }

    public function schedule()
    {
        return $this->hasOne(Schedule::class,'id','schedule_id')->with('user')->select('id','title','status','floor','region','person_id');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','person_id')->select('id','name');
    }

    public function role()
    {
        return $this->hasOne(Role::class,'id','role_id')->select('id','name');
    }

    
}
